﻿<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="tabSequences.ascx.cs"
    Inherits="CustomerService.SequenceTab" %>
<script type="text/javascript" language="javascript">
    function btnAddAdHoc_onclick() {
        TearOff("AddDetailItem.aspx?OwnerID=<%= _customer.OwnerID.ToString() %>&CustomerID=<%=_customer.CustomerID.ToString() %>&PanelID=<%= UpdatePanelSequences.UniqueID %>&Source=Sequence", "AddDetailItem", "600", "400");
    }
    function btnAddItem_onclick(SequenceStepID) {
        TearOff("AddDetailItem.aspx?OwnerID=<%= _customer.OwnerID.ToString() %>&SequenceOrderStepID=" + SequenceStepID + "&PanelID=<%= UpdatePanelSequences.UniqueID %>&Source=SequenceStep", "AddDetailItem", "600", "400");
    }
</script>
<asp:UpdatePanel ID="UpdatePanelSequences" runat="server">
<ContentTemplate>
<table>
    <tr>
        <td>
            <input id="btnAddSequence" type="button" runat="server" value="Add New Sequence..." />
            <br />
            <input id="btnAddAdHoc" type="button" value="Add Ad-Hoc Sequence..." runat="server" onclick="btnAddAdHoc_onclick();" />&nbsp&nbsp
            <br />
            <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" 
                TargetControlID="btnAddSequence" 
                PopupControlID="panelAddSequence" 
                DropShadow="true" 
                CancelControlID="btnAddCancel"  
                OkControlID="btnAddOK" 
                />
            <asp:ListView ID="lvSequenceList" runat="server" OnSelectedIndexChanging="SequenceListSelectedIndexChanging">
                <LayoutTemplate>
                    <table>
                        <tr id="itemPlaceholder" runat="server"></tr>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr id="Tr1" runat="server">
                        <td style="border-bottom: 1px solid black;">
                            <asp:LinkButton ID="btnSelectSequence" runat="server" Text='<%# (Eval("Sequence") == null) ? "Ad-Hoc" : Eval("Sequence.Description") %>' CommandName="Select" /><br />
                            <%# Eval("SequenceStatus.Description") %><br />
                            <%# Eval("CanceledReason.Description") %><br />
                        </td>
                    </tr>
                </ItemTemplate>
                <SelectedItemTemplate>
                    <tr id="Tr1" runat="server">
                        <td style="border-bottom: 1px solid black; background: yellow;">
                            <asp:LinkButton ID="btnSelectSequence" runat="server" Text='<%# (Eval("Sequence") == null) ? "Ad-Hoc" : Eval("Sequence.Description") %>' CommandName="Select" /><br />
                            <%# Eval("SequenceStatus.Description") %><br />
                            <%# Eval("CanceledReason.Description") %><br />
                        </td>
                    </tr>
                </SelectedItemTemplate>
            </asp:ListView>
        </td>
        <td valign="top">
            <asp:Repeater ID="repeater1" runat="server">
                <HeaderTemplate>
                    <table id="SequenceTable">
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <asp:Repeater ID="repeater2" runat="server" DataSource="<%#Container.DataItem %>">
                            <ItemTemplate>
                                <td class="SequenceRow">
                                    <table>
                                        <tr>
                                            <td>
                                                <asp:HiddenField ID="txtSequenceStepID" runat="server" Value='<%# Eval("SequenceOrderStepID") %>' />
                                                <%# (Eval("SequenceOrder.CreateDate") != null && ((short)Eval("RecurrenceCount") != 1)) ? "Started on " + ((DateTime)Eval("SequenceOrder.CreateDate")).ToShortDateString() + "<br />" : string.Empty%>
                                                <span style="display:<%#((short)Eval("Delay") > 0 && Eval("NextTriggerDate") == null) ? "inline" : "none" %>;">
                                                    Wait <asp:TextBox ID="txtSequenceDelay" runat="server" Text='<%# Eval("Delay") %>' /> days after previous step completes.<br />
                                                </span>
                                                This step will occur
                                                <asp:TextBox ID="txtRecurrenceCount" runat="server" Text='<%# Eval("RecurrenceCount") %>' />
                                                times (0 means indefinately) with
                                                <asp:TextBox ID="txtSequenceTerm" runat="server" Text='<%# Eval("RecurrenceTerm") %>' />
                                                days between each order.<br />
                                                The shipping charge is 
                                                <asp:TextBox ID="txtShipping" runat="server" Text='<%# Eval("Shipping") %>' />
                                                .<br />
                                                <span style="display:<%#(Eval("NextTriggerDate") != null) ? "inline" : "none" %>;">
                                                    The next order will be created on
                                                    <asp:TextBox ID="txtNextTriggerDate" runat="server" Text='<%# (Eval("NextTriggerDate") == null) ? string.Empty : ((DateTime)Eval("NextTriggerDate")).ToShortDateString() %>' />.
                                                    <br />
                                                </span>
                                                This step includes the following products:
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="5">
                                                <asp:Repeater ID="repeater3" runat="server" DataSource="<%# ((CustomerService.tblSequenceOrderStep)Container.DataItem).SequenceOrderStepProducts %>">
                                                    <HeaderTemplate>
                                                        <table style="border-top: 1px solid black;">
                                                            <tr style="font-weight: bold;">
                                                                <td>Qty</td>
                                                                <td>Product</td>
                                                                <td>Price</td>
                                                                <td>Discount</td>
                                                            </tr>
                                                    </HeaderTemplate>
                                                    <ItemTemplate>
                                                        <tr>
                                                            <td>
                                                                <asp:TextBox id="txtSequenceProductQty" runat="server"
                                                                    text='<%# Eval("Qty") %>' />
                                                            </td>
                                                            <td>
                                                                <%#Eval("Product.ShortName") %>
                                                            </td>
                                                            <td>
                                                                <%# (Eval("UnitPrice") == null) ? string.Empty : ((decimal)Eval("UnitPrice")).ToString("C") %>
                                                            </td>
                                                            <td>
                                                                <asp:TextBox id="txtSequenceProductDiscount" runat="server"
                                                                    text='<%# Eval("DisplayDiscount") %>' />
                                                            </td>
                                                            <td style="display:none;">
                                                                <asp:HiddenField ID="txtSequenceOrderStepProductID" runat="server" 
                                                                    Value='<%# Eval("SequenceOrderStepProductID") %>' />
                                                            </td>
                                                            <td style='display:<%# (_sequenceOrder == null) ? "none" : ((_sequenceOrder.CanEdit) ? "block" : "none") %>;'>
                                                                <asp:Button ID="btnRemove" runat="server" Text="Del" Width="40" 
                                                                 CommandName="Delete" CommandArgument='<%# Eval("SequenceOrderStepProductID") %>'
                                                                 OnCommand="btnRemove_Click"
                                                                />
                                                            </td>
                                                        </tr>
                                                    </ItemTemplate>
                                                    <FooterTemplate>
                                                        </table>
                                                    </FooterTemplate>
                                                </asp:Repeater>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style='display:<%# (_sequenceOrder == null) ? "none" : ((_sequenceOrder.CanEdit) ? "block" : "none") %>;'>
                                                <input id="btnAddItem" type="button" value="Add Item..."
                                                    onclick='btnAddItem_onclick( <%# Eval("SequenceOrderStepID") %> );' style="width: 100px;" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td style="vertical-align:middle">
                                    <nobr>--></nobr>
                                </td>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
            <div>
                Card Number :
                <asp:TextBox ID="txtCardNumber" runat="server" />
                <br />
                Card Expiration :
                <asp:TextBox ID="txtCardExpiration" runat="server" />
                <asp:CustomValidator ID="cstmCardExpiration" runat="server" 
                        ControlToValidate="txtCardExpiration" 
                        EnableClientScript="false" 
                        ErrorMessage="Invalid ExpirationDate" 
                        Display="None"
                        OnServerValidate="OnValidateExpiration" />
            </div>
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
            <asp:ModalPopupExtender ID="mpeCancel" runat="server" 
                TargetControlID="btnCancel" 
                PopupControlID="panelCancel" 
                DropShadow="true" 
                CancelControlID="btnCancelCancel"  
                />
        </td>
    </tr>
</table>
<div id="panelCancel" runat="server" class="modalPopup" style="display:none;">
    <h1>Select a cancel reason</h1>
    <br />
    <asp:DropDownList ID="ddCancelReason" runat="server" />
    <br />
    <asp:Button ID="btnCancelOK" Text="OK" runat="server" style="margin: 5px;" OnClick="btnCancelOK_Click" />
    <asp:Button ID="btnCancelCancel" Text="Cancel" runat="server" style="margin: 5px;" />
</div>
</ContentTemplate>
</asp:UpdatePanel>

<div id="panelAddSequence" runat="server" class="modalPopup" style="display:none;">
    <h1>Select a sequence to add</h1>
    <br />
    <asp:DropDownList ID="ddSequenceList" runat="server" />
    <br />
    <asp:Button ID="btnAddOK" Text="OK" runat="server" style="margin: 5px;" OnClick="btnAddOK_Click" />
    <asp:Button ID="btnAddCancel" Text="Cancel" runat="server" style="margin: 5px;" />
</div>